package com.lc.question.dao;

import com.lc.question.constant.MyConstants;
import com.lc.question.pojo.Question;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository("questionDao")
public interface IQuestionDao {

    //查询某个问卷表包含的所有问题，按编号顺序排序
    @Select("select * from question where tab_Id=#{tab_Id} and user_id=" + MyConstants.PUB_PEPOPLE + " and que_status=" + MyConstants.QUE_Q + " order by num_Id")


    public List<Question> questionList(int tab_Id);

    //查询每个题的选项
    @Select("select que_content from question where tab_Id=#{arg0} num_Id=#{arg1} and que_status=" + MyConstants.STATE_PUB + " order by num_Id")
    public String question_content(int tab_Id, int num_Id);


    //查询每个题的选项的填写占比
    @Select("select count(que_content) from question where tab_Id=#{arg0} and num_Id=#{arg1} and que_status=" + MyConstants.STATE_USER + " order by num_Id")
    public int questionList2(int tab_Id, int num_Id);

    //查询每个题的选项的填写占比
    @Select("select count(*) from question where que_content=#{arg0} and tab_Id=#{arg1} and num_Id=#{arg2} and que_status=" + MyConstants.STATE_USER + " order by num_Id")
    public int questionList3(String que_content, int tab_Id, int num_Id);

    //新增问题(包含发布和填写)
    @Insert("insert into question(num_Id,plan_Id,user_Id,tab_Id,que_title,que_content,que_status,que_type,grade,b_must,b_other,t_text) " +
            "values(#{num_Id},#{plan_Id},#{user_Id},#{tab_Id},#{que_title},#{que_content},#{que_status}" +
            ",#{que_type},#{grade},#{b_must},#{b_other},#{t_text})")
    public void addQuestion(Question question);


    @Update("update question set num_Id=#{num_Id},que_title=#{que_title} " +
            "que_content=#{que_content},que_status=#{que_status}," +
            "que_type=#{que_type},grade=#{grade}," +
            "b_must=#{b_must},b_other=#{b_other},t_text=#{t_text} where que_Id=#{que_Id}")
    public void updateQuestion(Question question);

    @Delete("delete * from question where tab_Id=#{tab_Id}")
    public void deleteQuestion(int tab_Id);

    @Delete("delete * from question where plan_Id=#{plan_Id}")
    public void deleteQueByPlanId(int plan_Id);

    @Delete("delete * from question where tab_Id=#{tab_Id} and user_Id=#{user_Id}")
    public void deleteQuestion2(int tab_Id, String user_Id);

    @Select("select * from question where plan_Id=#{plan_Id} and que_status=" + MyConstants.QUE_Q)
    public List<Question> queList3(int plan_Id);

    @Select("select * from question where plan_Id=#{arg0} and user_Id=#{arg1} and que_status=" + MyConstants.QUE_A)
    public List<Question> queList4(int plan_Id,String user_Id);



}
